;(function($) {
    $.fn.unserializeArray = function(data) {
        var obj = this;

        var setValueByType = function(element, name, value){
            var elementType = element.attr("type");
            switch (elementType)
            {
                case "text":
                case "password":
                case "hidden":
                case "button":
                    element.val(value);
                    break;
                case "radio":
                case "checkbox":
                    setValueElements(element, value);
                    break;
                default:
                    element.data(name, value);
            }
        }

        var setValueElements = function(element, value){
            var values = value.toString().split(",");
            element.each(function() {
                if ($.inArray($(this).val(), values) != -1) {
                    $(this).prop("checked", true);
                }
            });
        }

        $.each(data, function( name, value ) {
            var element = obj.find("[name='"+name+"']");
            if ($.isEmptyObject(element)) {
                return true;
            }

            var elementNodeName = element.prop('nodeName');
            switch (elementNodeName)
            {
                case "SELECT":
                case "TEXTAREA":
                    element.val(value);
                    break;
                case "INPUT":
                    setValueByType(element, name, value);
                    break;
                case "BUTTON":
                    element.html(value);
                    break;
                default:
                    element.data(name, value);
            }
        });
        return this;
    }
})(jQuery);